<template>
  <div class="recommend">
    <h2 class="title">精品推荐</h2>
    <div class="recommend-items">
      <div class="item" @click="clickItem(item.id)" v-for="item in items" :key="item.id">
        <img class="item-pic" v-lazy="item.pic" alt="">
        <div class="item-info">
          <h5>{{ item.name | subStr }}</h5>
          <p>{{item.characteristic | subStr}}</p>
          <div class="item-action">
            <p class="price">{{ item.minPrice | currency('￥') }}</p>
            <van-icon
              @click.stop="clickAddItem(item)"
             class-prefix="icon" name="jia-tianchong

"></van-icon>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { currency, subStr } from '@/filters'

export default {
  props: {
    items: {
      type: Array,
      required: true
    }
  },
  methods: {
    clickItem (id) {
      this.$emit('clickItem', id)
    },
    clickAddItem (item) {
      // 点击加入购物车按钮
      this.$emit('clickAddItem', item)
    }
  },
  filters: {
    currency,
    subStr
  }
}
</script>

<style lang="scss" scoped>
.title{
  line-height: 50px;
  color: #333;
  font-size: 14px;
  padding-left: 15px;
}
.recommend-items{
  .item{
    height: 180px;
    display: flex;
    background-color: #fff;
    margin-top:10px;
    .item-pic{
      width: 180px;
      height: 180px;
    }
    .item-info{
      flex:1;
      height: 180px;
      display: flex;
      flex-direction: column;
      padding:0 10px;
      h5{
        color:#333;
        font-size: 14px;
        line-height: 30px;
      }
      p{
        font-size: 12px;
        line-height: 28px;
        color:#666;
      }
      .item-action{
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .price{
          font-size: 16px;
          color:#f66;
        }
        .icon{
          font-size: 20px;
          color:#f66;
        }
      }
    }
  }
}

</style>
